#include <bits/stdc++.h>
using namespace std;
int n = 0;
int arr [1012];
bool vis [1012];

void dfs(int x) {
	if (x == n) {
		int i;
		for (i = 0; i <= n - 1; i++) {
			if (i == n - 1)
				cout << arr[i] << endl;
			else
				cout << arr[i] << " ";
		}
	} else {
		for (int i = 1; i <= n; i++) {
			if (!vis[i]) {
				arr[x] = i;
				vis[i] = true;
				dfs(x + 1);
				vis[i] = false;
			}
		}
	}
}

int main() {
	cin >> n;
	dfs(0);
	//cout << "Full arrangement of 1~8";
	return 0;
}